package org.yu.register;

import net.minecraft.client.renderer.ItemBlockRenderTypes;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.core.Direction;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.BlockTags;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.Tiers;
import net.minecraft.world.level.block.*;
import net.minecraft.world.level.block.grower.JungleTreeGrower;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraftforge.client.model.generators.BlockStateProvider;
import net.minecraftforge.client.model.generators.ConfiguredModel;
import net.minecraftforge.client.model.generators.ItemModelProvider;
import net.minecraftforge.client.model.generators.ModelFile;
import net.minecraftforge.common.Tags;
import org.yu.Yu;
import org.yu.api.blocks.data.BlockFacingFor4Side;
import org.yu.api.register.BlockHolder;
import org.yu.api.register.ItemHolder;
import org.yu.api.register.LazyRegistry;
import org.yu.api.util.ModelUtil;
import org.yu.register.machine.StoveBlock;

import java.util.function.BiConsumer;

@SuppressWarnings("all")
public class BlockRegister {
    private final static LazyRegistry registry= Yu.LAZYREGISTRY;
    public final static BlockHolder<Block> cabientCreative=registry.block("cabient_creative",Block::new)
            .axe()
            .tier(Tiers.STONE)
            .name("zh_cn","创造药柜")
            .build();
    public final static BlockHolder<Block> fire_altar=registry.block("fire_altar",Block::new)
            .axe().pickaxe()
            .tier(Tiers.IRON).name("zh_cn","煜火祭坛")
            .propertie(properties -> properties.lightLevel(state->15))
            .build();
    public final static BlockHolder<Block> jadeBlock=registry.block("jade_block",Block::new)
            .pickaxe()
            .tier(Tiers.IRON)
            .name("zh_cn","玉块")
            .build();
    public final static BlockHolder<Block> jadeOre=registry.block("jade_ore",Block::new)
            .pickaxe()
            .tier(Tiers.IRON)
            .loot((blockHolder, lazyBlockLoot) -> lazyBlockLoot.dropOther(blockHolder.get(), ItemRegister.jade))
            .name("zh_cn","玉矿")
            .build();
    public final static BlockHolder<LeavesBlock> lacquerLeaves=registry.block("lacquer_leaves",LeavesBlock::new)
            .propertie(properties -> properties.noOcclusion().sound(SoundType.CROP))
            .tag(BlockTags.LEAVES)
            .itemProperties(Item.Properties::fireResistant)
            .name("zh_cn","漆树叶")
            .build();
    public final static BlockHolder<RotatedPillarBlock> lacquerLog=registry.block("lacquer_log",RotatedPillarBlock::new)
            .tag(BlockTags.LOGS)
            .tag(BlockTags.LOGS_THAT_BURN)
            .name("zh_cn","漆树原木")
            .axe()
            .state((provider, blockHolder) -> provider.logBlock((RotatedPillarBlock) blockHolder.get()))
            .itemProperties(Item.Properties::fireResistant)
            .build();
    public final static BlockHolder<RotatedPillarBlock> strippedLacquerLog=registry.block("stripped_lacquer_log",RotatedPillarBlock::new)
            .tag(BlockTags.LOGS)
            .tag(BlockTags.LOGS_THAT_BURN)
            .axe()
            .state((provider, blockHolder) -> provider.logBlock((RotatedPillarBlock) blockHolder.get()))
            .itemProperties(Item.Properties::fireResistant)
            .name("zh_cn","剥皮漆树原木")
            .build();
    public final static BlockHolder<Block> lacquerPlank=registry.block("lacquer_plank",Block::new)
            .axe()
            .itemProperties(Item.Properties::fireResistant)
            .tag(BlockTags.PLANKS)
            .name("zh_cn","漆木板")
            .build();
    public final static BlockHolder<SaplingBlock> lacquerSapling=registry.block("lacquer_sapling",properties -> new SaplingBlock(new JungleTreeGrower(),properties))
            .axe()
            .tag(BlockTags.SAPLINGS)
            .itemProperties(Item.Properties::fireResistant)
            .propertie(BlockBehaviour.Properties::noOcclusion)
            .state(ModelUtil.plantModel())
            .itemModel(ModelUtil.useBlockTexture())
            .name("zh_cn","漆树苗")
            .build();
    public final static BlockHolder<WoodButtonBlock> lacquerButton=registry.block("lacquer_button",WoodButtonBlock::new)
            .itemProperties(Item.Properties::fireResistant)
            .propertie(BlockBehaviour.Properties::noOcclusion)
            .axe()
            .state((provider, blockHolder) -> {
                var block = blockHolder.get().getRegistryName();
                provider.buttonBlock((ButtonBlock) blockHolder.get(), new ResourceLocation(block.getNamespace(), "block/lacquer_plank"));
            })
            .itemModel((provider, itemHolder) -> {
                var item = itemHolder.get().getRegistryName();
                provider.buttonInventory(item.toString(), new ResourceLocation(item.getNamespace(), "block/lacquer_plank"));
            })
            .name("zh_cn","漆木按钮")
            .build();
    public final static BlockHolder<DoorBlock> lacquerDoor=registry.block("lacquer_door",DoorBlock::new)
            .axe()
            .propertie(BlockBehaviour.Properties::noOcclusion)
            .itemProperties(Item.Properties::fireResistant)
            .state((provider, blockHolder) -> {
                var block = blockHolder.get().getRegistryName();
                provider.doorBlock((DoorBlock) blockHolder.get(), new ResourceLocation(block.getNamespace(), "block/" + block.getPath()+"_bottom"), new ResourceLocation(block.getNamespace(), "block/" + block.getPath() + "_top"));
            })
            .itemModel((provider, itemHolder) -> provider.basicItem(itemHolder.asItem()))
            .name("zh_cn","漆木门")
            .build();
    public final static BlockHolder<TrapDoorBlock> lacquerTrapdoor=registry.block("lacquer_trapdoor",TrapDoorBlock::new)
            .axe()
            .propertie(BlockBehaviour.Properties::noOcclusion)
            .itemProperties(Item.Properties::fireResistant)
            .state((provider, blockHolder) -> {
                var block = blockHolder.get().getRegistryName();
                provider.trapdoorBlock((TrapDoorBlock) blockHolder.get(), new ResourceLocation(block.getNamespace(), "block/" + block.getPath()),true);
            })
            .itemModel((provider, itemHolder) -> {
                var name = itemHolder.get().getRegistryName().getPath();
                provider.withExistingParent(name, new ResourceLocation(itemHolder.get().getRegistryName().getNamespace(), "block/" + name + "_bottom"));
            })
            .name("zh_cn","漆木活板门")
            .build();




    public static void init(){
        registry.executeWhenClientSetup(()->{
            ItemBlockRenderTypes.setRenderLayer(lacquerLeaves.get(), RenderType.cutoutMipped());
            ItemBlockRenderTypes.setRenderLayer(lacquerDoor.get(), RenderType.cutoutMipped());
            ItemBlockRenderTypes.setRenderLayer(lacquerSapling.get(), RenderType.cutoutMipped());
            ItemBlockRenderTypes.setRenderLayer(lacquerTrapdoor.get(), RenderType.cutoutMipped());
        });
    }

}
